﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;

namespace wUniApp.MVC.Helpers
{
  public static class WebViewPageExtensions
  {
    public static T GetUrlData<T>(this WebViewPage page, string name, T defaultValue = default(T))
    {
      int idx = page.UrlData.IndexOf(name);
      return GetUrlData(page, idx, defaultValue);
    }
    public static T GetUrlData<T>(this WebViewPage page, int index, T defaultValue = default(T))
    {
      try
      {
        return (T)Convert.ChangeType(page.UrlData[index], typeof(T));
      }
      catch
      {
        return defaultValue;
      }
    }
    public static T GetRequestData<T>(this WebViewPage page, string valueName, T defaultValue = default(T))
    {
      try
      {
        if (!String.IsNullOrEmpty(page.Request[valueName]))
        {
          return (T)Convert.ChangeType(page.Request[valueName], typeof(T));
        }
        return defaultValue;
      }
      catch
      {
        return defaultValue;
      }
    }

  }
}